package com.hr.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hr.dao.DepartmentDao;
import com.hr.model.DepartmentModel;
import com.hr.service.DepartmentService;
import com.sun.xml.internal.ws.util.StringUtils;

/**
 * 部门管理Service实现类
 * @author fazhen.zheng
 *
 */
@Service
public class DepartmentServiceImpl implements DepartmentService{
	@Autowired
	private DepartmentDao departmentDao;

	@Override
	public boolean  editDepartment(DepartmentModel departmentModel) {
		if(departmentModel==null)
			return false;
		String code = departmentModel.getCode();
		if(code==null||"".equals(code.trim())){
			//增加部门
			departmentDao.insert(departmentModel);
		}else{
			//修改部门
			departmentDao.update(departmentModel);
		}
			
		return true;
	}

	@Override
	public List<DepartmentModel> findAll() {
		List<DepartmentModel> departments = departmentDao.queryAll();
		return departments;
	}

	@Override
	public boolean removeDeparment(String code) {
		if(!"".equals(code)){
			return departmentDao.delete(code);
		}
		return false;	
	}

	@Override
	public DepartmentModel findByPrimaryKey(String code) {
		if(code==null||"".equals(code.trim()))
			return null;
		return departmentDao.queryByPrimaryKey(code);
	}
	
}
